import React, { PureComponent } from 'react'
import { StyleSheet, View, Text, Image, TouchableOpacity } from 'react-native'
import screen from '../../../../common/screen'
import HotProductItem from './HotProductItem';
type Props = {
    infos: Array,//新品推荐的数据
    OnPressMore: Function,//点击更多的事件
    OnPressItem: Function,//点击商品的事件
}



class HotProduct extends PureComponent<>{
    constructor(props) {
        super(props)
    }
    render() {
        let infos = []
        //只取前四个
        if (this.props.infos.length > 3) {
            for (let i = 0; i < 4; ++i) {
                infos.push(this.props.infos[i])
            }
        } else {
            for (let i = 0; i < this.props.infos.length; ++i) {
                infos.push(this.props.infos[i])
            }
        }

        return (
            this.props.infos.length > 0 ?
                <View >
                    <TouchableOpacity onPress={()=>this.props.OnPressMore('3')}>
                        <Image source={require('../../../../img/home/recommend_HotProduct.png')} style={styles.icon} />
                    </TouchableOpacity>
                    <View style={styles.contain}>
                        {infos.map((item, i) => (
                            <HotProductItem
                                info={item}
                                key={i}
                                OnPress={this.props.OnPressItem}
                            />
                        ))}
                    </View>
                </View>
                : <View ></View>
        );
    }
}
const styles = StyleSheet.create({
    contain: {
        flexWrap: 'wrap',
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        marginLeft:7,
        marginRight:7,
    },
    icon: {
        width: screen.width - 14,
        height: screen.width * 0.11,
       // marginTop: 2,
        marginLeft: 7,
        marginRight: 7,
        backgroundColor: 'white',
        resizeMode: 'contain',
    },
})

export default HotProduct